(library (request-utils)
  (export request-path-components)
  (import
    (rnrs base)
    (only (guile) lambda* λ)
    ;; Guile exception handling
    (ice-9 exceptions)
    (ice-9 session)
    ;; web server, concurrent
    (fibers web server)
    ;; standard web library
    (web request)
    (web response)
    (web uri)
    (sxml simple)
    ;; custom modules
    (prefix (logging) log:)))


(define request-path-components
  (λ (request)
    "Split a given request path up into its components. A
request path is the route after the domain and host
part. For example for
http://localhost:8080/part1/part2/?blub=123 the result will
be the list of containing the string part1 and the string
part2."
    ;; split the string that represents the uri and decode
    ;; any url-endoced things
    ;; /part1/part2/ --> '("part1" "part2")
    (split-and-decode-uri-path
     ;; get the uri path as a string from the request struct
     ;; http://localhost:8080/part1/part2/?blub=123 --> /part1/part2/
     (uri-path
      ;; get the request-uri struct:
      ;; http://localhost:8080/abc/def/?abc=123 -->
      ;; #<<uri> scheme: #f userinfo: #f host: #f port: #f path: "/abc/def/"
      ;; query: "abc=123" fragment: #f>
      (request-uri request)))))
